<?php
 class ClassAction extends Action{
 	public function index(){
 		$class=M('Class');
 		Import('ORG.Util.Page');
 		$count=$class->count();
 		$page=new Page($count,10);
 		$show=$page->show();
 		$rows=$class->limit($page->firstRow.','.$page->listRows)->select();
 		$this->assign('show',$show);
 		$this->assign('rows',$rows);
 		$this->display();
 	}
 	// 添加模版
 	public function add(){
 		$this->display();
 	}
 	// 添加操作
 	public function add_handle(){
 		$class=M('Class');
 		if($class->create()){
 			$class->add();
 			$this->redirect('index');
 		}else{
 			$this->error('添加失败');
 		};
 	}

 	// 删除
 	public function delete(){
 		$class=M('Class');
 		// 获取$.get传过来的id
 		$id=$_GET['id'];
		$re=$class->delete($id);
		if($re){
			$arr['status']=1;
			$arr['info']='删除成功';
			echo json_encode($arr);
		}
 		
 		
 	}


 	// 修改模版
 	public function edit(){
 		$class=M('Class');
 		$id=$_GET['id'];
 		$row=$class->find($id);
 		$this->assign('row',$row);
 		$this->display();
 	}
 	// 修改操作
 	public function edit_handle(){
 		$class=M('Class');
 		if($class->create()){
 			$class->save();
 			$this->redirect('index');
 		};
 	}
 }
?>